(graphcache) - Alias resolvers/updates parent to its parentKey in cache methods #1208
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #1207
Summary
This updates the shared context object to be provided on a global ref, which is then used in various cache methods, via
cache.keyOfEntity
, to alias theparent
argument, which can be found on resolvers and updaters, toinfo.parentKey
. This is done by adding (publicly)info.parent
, which is the current parent's data as it is. (This avoids us having to share it on a separate object)This further refactors
store.keyOfEntity
to take care of all key normalisation that has been done repeatedly in separate methods before, which further ensures thatcache[method](parent)
is going to work consistently as expected.The reasoning here is that writing resolvers with
parent
as the first argument to further cache methods is so intuitive that we even did it ourselves in the docs, without thinking about it, although its support wasn't guaranteed as #1185 demonstrates. As an example:Set of changes
parent
field toContext
andResolveInfo
Context
to be exposedstore.keyOfEntity
alias ifentity === ctx.parent
toctx.parentKey